package com.kymatrix.kycarbon.xsmd.system.server.outer;

import com.kymatrix.kycarbon.xsmd.system.server.model.entity.OperateLogEntity;
import com.kymatrix.kycarbon.xsmd.system.server.service.IOperateLogService;
import com.kymatrix.kycarbon.xsmd.system.api.dto.SaveOperateLogDto;
import com.kymatrix.kycarbon.xsmd.system.api.service.OperateLogApi;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author liujie
 * @date 2024-04-17
 */
@Component
@Slf4j
public class OperateLogApiImpl implements OperateLogApi {
    
    @Resource
    private IOperateLogService operateLogService;
    
    @Override
    @Async("asyncExecutor")
    public void saveOperateLog(SaveOperateLogDto dto) {
        OperateLogEntity entity = new OperateLogEntity();
        entity.setUserId(dto.getUserId());
        entity.setUsername(dto.getUsername());
        entity.setType(dto.getType());
        entity.setSubType(dto.getSubType());
        entity.setExtra(dto.getExtra());
        entity.setRequestMethod(dto.getRequestMethod());
        entity.setRequestUrl(dto.getRequestUrl());
        entity.setUserIp(dto.getUserIp());
        entity.setUserAgent(dto.getUserAgent());
        entity.setElapsedTime(dto.getElapsedTime());
        entity.setTenantId(dto.getTenantId());
        entity.setRequestParams(dto.getRequestParams());
        entity.setResultCode(dto.getResultCode());
        entity.setResultMsg(dto.getResultMsg());
        entity.setExceptionInfo(dto.getExceptionInfo());
        operateLogService.save(entity);
    }
}
